using System;
using dnAnalytics.Nli;

/// <summary>
/// Rank-1 update of complex matrix. a = alpha*x*Conjugate(y') + a
/// </summary>
internal class Program {
	[STAThread]
	private static void Main() {
		//use the MKL BLAS provider
		IBlas blas = Blas.Provider(BlasProvider.Mkl);

		//column ordering
		ComplexDouble[] a = new ComplexDouble[] {
			new ComplexDouble(1, 1), new ComplexDouble(2, 2), new ComplexDouble(3, 3),
			new ComplexDouble(1, 1), new ComplexDouble(2, 2), new ComplexDouble(3, 3),
			new ComplexDouble(1, 1), new ComplexDouble(2, 2), new ComplexDouble(3, 3)
		};
		ComplexDouble[] x = new ComplexDouble[] {new ComplexDouble(1, 1), new ComplexDouble(1, 1), new ComplexDouble(1, 1)};
		ComplexDouble[] y = new ComplexDouble[] {new ComplexDouble(1, 1), new ComplexDouble(1, 1), new ComplexDouble(1, 1)};
		double alpha = 1;
		int lda = 3;

		//this will basically add 2 to each element of a, since (1+i)*Conjugate(1+i) = 2.
		blas.Zgerc(BlasOrderType.Column, 3, 3, alpha, x, 1, y, 1, a, lda);
		foreach (ComplexDouble value in a) {
			Console.WriteLine(value.ToString());
		}
		Console.WriteLine();
		/* 
		Output:
		3 + 1i
		4 + 2i
		5 + 3i
		3 + 1i
		4 + 2i
		5 + 3i
		3 + 1i
		4 + 2i
		5 + 3i		
		*/
	}
}